#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define endl '\n'

void solve() {
    stack<ull> stk;
    int n; cin >> n;
    while (n--) {
        string s; cin >> s;
        if (s == "push") {
            ull x; cin >> x;
            stk.push(x);
        }
        else if (s == "pop") {
            if (stk.empty()) cout << "Empty" << endl;
            else stk.pop();
        }
        else if (s == "query") {
            if (stk.empty()) cout << "Anguei!" << endl;
            else cout << stk.top() << endl;
        }
        else cout << stk.size() << endl;
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t; cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}